From af7af769b97af63b70e38b607dc389d1b689e8bc Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Mon, 23 Nov 2009 07:00:08 +0000 Subject: [PATCH] libxenlight: correct broken osdeps.[ch] and make #includes consistent osdeps.[hc] previously mistakenly declared and defined [v]asprintf. These functions are available in the libc on most platforms. Also, osdeps.h is used by xc.c but xc.c is not part of the library, so osdeps.h is part of the public interface and should have a better name. So now, instead: * osdeps.h is libxl_osdeps.h. * _GNU_SOURCE is #defined in libxl_osdeps.h so that we get the system [v]asprintf (and various other functions) * libxl_osdeps.h is included first in every libxl*.c file (it needs to be before any system headers so that _GNU_SOURCE) takes effect. * osdeps.[hc] only provide their own reimplementation of [v]asprintf if NEED_OWN_ASPRINTF is defined. Currently it is not ever defined but this is provided for any platform which needs it. * While I was editing the #includes in each .c file, I put them all into the same order: "libxl_osdeps.h", then system headers, then local headers. * xs.h is included in libxl.h. This is needed for "bool"; it has to not be typedefed in libxl.h because otherwise we get a duplicate definition when including xs.h. Signed-off-by: Ian Jackson --- tools/libxl/Makefile | 3 +-- tools/libxl/libxl.c | 3 +++ tools/libxl/libxl.h | 5 ++--- tools/libxl/libxl_device.c | 7 +++++-- tools/libxl/libxl_dom.c | 16 ++++++++++------ tools/libxl/libxl_exec.c | 3 +++ tools/libxl/libxl_internal.c | 10 +++++++--- tools/libxl/{osdeps.h => libxl_osdeps.h} | 11 +++++++++-- tools/libxl/libxl_utils.c | 6 ++++-- tools/libxl/libxl_xshelp.c | 7 +++++-- tools/libxl/osdeps.c | 4 ++++ tools/libxl/xl.c | 7 +++++-- 12 files changed, 58 insertions(+), 24 deletions(-) rename tools/libxl/{osdeps.h => libxl_osdeps.h} (80%) diff --git a/tools/libxl/Makefile b/tools/libxl/Makefile index 492d6d9151..0358cea7b5 100644 --- a/tools/libxl/Makefile +++ b/tools/libxl/Makefile @@ -23,8 +23,7 @@ LIBCONFIG_URL ?= http://www.hyperrealm.com/libconfig LIBCONFIG_SOURCE = libconfig-1.3.2 LIBCONFIG_OUTPUT = $(LIBCONFIG_SOURCE)/.libs -LIBXL_OBJS-y = -LIBXL_OBJS-$(CONFIG_Linux) += osdeps.o +LIBXL_OBJS-y = osdeps.o LIBXL_OBJS = flexarray.o libxl.o libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o libxl_internal.o xenguest.o libxl_utils.o $(LIBXL_OBJS-y) CLIENTS = xl diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 2eea3a8138..c20025ff90 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -14,6 +14,8 @@ * GNU Lesser General Public License for more details. */ +#include "libxl_osdeps.h" + #include #include #include @@ -25,6 +27,7 @@ #include /* for write, unlink and close */ #include #include + #include "libxl.h" #include "libxl_utils.h" #include "libxl_internal.h" diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 0c6f168fee..ac4c79e39c 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -15,14 +15,13 @@ #ifndef LIBXL_H #define LIBXL_H -#include "osdeps.h" #include #include #include #include -#include "xen_uuid.h" +#include -typedef int bool; +#include "xen_uuid.h" typedef void (*libxl_log_callback)(void *userdata, int loglevel, const char *file, int line, const char *func, char *s); diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c index 82a2a30580..451233fd4f 100644 --- a/tools/libxl/libxl_device.c +++ b/tools/libxl/libxl_device.c @@ -14,15 +14,18 @@ * GNU Lesser General Public License for more details. */ +#include "libxl_osdeps.h" + #include #include -#include "libxl.h" -#include "libxl_internal.h" #include /* for struct timeval */ #include #include #include +#include "libxl.h" +#include "libxl_internal.h" + char *string_of_kinds[] = { [DEVICE_VIF] = "vif", [DEVICE_VBD] = "vbd", diff --git a/tools/libxl/libxl_dom.c b/tools/libxl/libxl_dom.c index e3cf4374c5..68b2b21378 100644 --- a/tools/libxl/libxl_dom.c +++ b/tools/libxl/libxl_dom.c @@ -13,17 +13,21 @@ * GNU Lesser General Public License for more details. */ -#include "libxl.h" -#include "libxl_internal.h" +#include "libxl_osdeps.h" + #include #include -#include -#include -#include #include #include /* for struct timeval */ #include /* for sleep(2) */ +#include +#include +#include + +#include "libxl.h" +#include "libxl_internal.h" + int is_hvm(struct libxl_ctx *ctx, uint32_t domid) { xc_domaininfo_t info; @@ -110,7 +114,7 @@ int build_pv(struct libxl_ctx *ctx, uint32_t domid, dom = xc_dom_allocate(info->u.pv.cmdline, info->u.pv.features); if (!dom) { - XL_LOG_ERRNOVAL(ctx, XL_LOG_ERROR, dom, "xc_dom_allocate failed"); + XL_LOG_ERRNO(ctx, XL_LOG_ERROR, "xc_dom_allocate failed"); return -1; } if ((ret = xc_dom_linux_build(ctx->xch, dom, domid, info->max_memkb / 1024, diff --git a/tools/libxl/libxl_exec.c b/tools/libxl/libxl_exec.c index 8a589b676c..5186ac8c7c 100644 --- a/tools/libxl/libxl_exec.c +++ b/tools/libxl/libxl_exec.c @@ -15,9 +15,12 @@ * GNU Lesser General Public License for more details. */ +#include "libxl_osdeps.h" + #include #include #include + #include "libxl.h" #include "libxl_internal.h" diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c index 7ba0c9790f..a04ac8ddf7 100644 --- a/tools/libxl/libxl_internal.c +++ b/tools/libxl/libxl_internal.c @@ -12,13 +12,17 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. */ -#include "libxl.h" -#include "libxl_internal.h" -#include "libxl_utils.h" + +#include "libxl_osdeps.h" + #include #include #include +#include "libxl.h" +#include "libxl_internal.h" +#include "libxl_utils.h" + int libxl_error_set(struct libxl_ctx *ctx, int code) { return 0; diff --git a/tools/libxl/osdeps.h b/tools/libxl/libxl_osdeps.h similarity index 80% rename from tools/libxl/osdeps.h rename to tools/libxl/libxl_osdeps.h index 5391727fa7..fc453c3553 100644 --- a/tools/libxl/osdeps.h +++ b/tools/libxl/libxl_osdeps.h @@ -13,14 +13,21 @@ * GNU Lesser General Public License for more details. */ +/* + * This header must be included first, before any system headers, + * so that _GNU_SOURCE takes effect properly. + */ + #ifndef LIBXL_OSDEP #define LIBXL_OSDEP +#define _GNU_SOURCE + +#ifdef NEED_OWN_ASPRINTF #include -#if defined(__linux__) int asprintf(char **buffer, char *fmt, ...); int vasprintf(char **buffer, const char *fmt, va_list ap); -#endif +#endif /*NEED_OWN_ASPRINTF*/ #endif diff --git a/tools/libxl/libxl_utils.c b/tools/libxl/libxl_utils.c index 5048fd06aa..c174d0f510 100644 --- a/tools/libxl/libxl_utils.c +++ b/tools/libxl/libxl_utils.c @@ -13,8 +13,8 @@ * GNU Lesser General Public License for more details. */ -#include "libxl_utils.h" -#include "libxl_internal.h" +#include "libxl_osdeps.h" + #include #include #include @@ -24,6 +24,8 @@ #include #include +#include "libxl_utils.h" +#include "libxl_internal.h" unsigned long libxl_get_required_shadow_memory(unsigned long maxmem_kb, unsigned int smp_cpus) diff --git a/tools/libxl/libxl_xshelp.c b/tools/libxl/libxl_xshelp.c index f59eee7523..87c494a4a5 100644 --- a/tools/libxl/libxl_xshelp.c +++ b/tools/libxl/libxl_xshelp.c @@ -13,13 +13,16 @@ * GNU Lesser General Public License for more details. */ +#include "libxl_osdeps.h" + #include #include -#include "libxl.h" -#include "libxl_internal.h" #include #include +#include "libxl.h" +#include "libxl_internal.h" + char **libxl_xs_kvs_of_flexarray(struct libxl_ctx *ctx, flexarray_t *array, int length) { char **kvs; diff --git a/tools/libxl/osdeps.c b/tools/libxl/osdeps.c index 81175aa328..ad96480a85 100644 --- a/tools/libxl/osdeps.c +++ b/tools/libxl/osdeps.c @@ -19,6 +19,8 @@ #include #include +#ifdef NEED_OWN_ASPRINTF + int vasprintf(char **buffer, const char *fmt, va_list ap) { int size = 0; @@ -60,3 +62,5 @@ int asprintf(char **buffer, char *fmt, ...) va_end (ap); return status; } + +#endif diff --git a/tools/libxl/xl.c b/tools/libxl/xl.c index 3b735ec78a..727fe4a837 100644 --- a/tools/libxl/xl.c +++ b/tools/libxl/xl.c @@ -14,8 +14,8 @@ * GNU Lesser General Public License for more details. */ -#include "libxl.h" -#include "libxl_utils.h" +#include "libxl_osdeps.h" + #include #include #include @@ -29,6 +29,9 @@ #include #include +#include "libxl.h" +#include "libxl_utils.h" + void log_callback(void *userdata, int loglevel, const char *file, int line, const char *func, char *s) { fprintf(stderr, "[%d] %s:%d:%s: %s\n", loglevel, file, line, func, s); -- 2.30.2